package com.handler;

import com.Config;
import com.UploadQueue;
import com.amazonaws.services.s3.model.DeleteObjectsRequest;
import com.amazonaws.services.s3.transfer.MyTransferManager;
import com.entity.PackCmd;

public class PackHandler extends BaseHandler {

    public PackHandler(MyTransferManager transferManager) {
        super(transferManager);
    }

    @Override
    protected void execute() {
        System.out.println("执行删除操作");

        PackCmd packCmd = Config.dataManage.getPackCmd();

        if (packCmd.deleteFileList != null && packCmd.deleteFileList.size() > 0) {
            System.out.println("删除数量 len="+packCmd.deleteFileList.size());
            DeleteObjectsRequest deleteObjectsResult = new DeleteObjectsRequest(packCmd.bucketName)
                    .withKeys(packCmd.deleteFileList);
            s3Client.deleteObjects(deleteObjectsResult);
        }

        System.out.println("全部删除完成！");

        System.out.println("执行上传操作");

        UploadQueue.create()
                .setTransferManager(transferManager)
                .startUpload(packCmd.uploadFileList);

        System.out.println("全部上传完成！");

        // 关闭client
        transferManager.shutdownNow();

    }



}
